import { request } from "@/http/axios"
import type { 
  ShopItem, 
  GetShopsRequestData, 
  GetShopsResponseData, 
  CreateShopRequestData, 
  UpdateShopRequestData,
  ShopStatsData
} from "./type"

/** 获取商铺列表 */
export function getShopsApi(params?: GetShopsRequestData) {
  return request<GetShopsResponseData>({
    url: "shops",
    method: "get",
    params
  })
}

/** 获取商铺详情 */
export function getShopApi(id: string) {
  return request<ShopItem>({
    url: `shops/${id}`,
    method: "get"
  })
}

/** 创建商铺 */
export function createShopApi(data: CreateShopRequestData) {
  return request<ShopItem>({
    url: "shops",
    method: "post",
    data
  })
}

/** 更新商铺信息 */
export function updateShopApi(id: string, data: UpdateShopRequestData) {
  return request<ShopItem>({
    url: `shops/${id}`,
    method: "put",
    data
  })
}

/** 删除商铺 */
export function deleteShopApi(id: string) {
  return request({
    url: `shops/${id}`,
    method: "delete"
  })
}

/** 获取商铺统计数据 */
export function getShopStatsApi() {
  return request<ShopStatsData>({
    url: "shops/stats",
    method: "get"
  })
}

/** 获取商铺排行榜 */
export function getShopRankingApi(type: 'fast' | 'slow' = 'fast', limit: number = 10) {
  return request<ShopItem[]>({
    url: "shops/ranking",
    method: "get",
    params: { type, limit }
  })
}